package top.tangyh.lamp.care.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.tangyh.lamp.care.entity.IcuOnlinePatients;
import top.tangyh.lamp.care.mapper.IcuOnlinePatientsMapper;
import top.tangyh.lamp.care.service.IcuOnlinePatientsService;

import java.util.List;

/**
 * @author: zqb
 * @date: 2024/12/9 16:27
 */
@Service
@RequiredArgsConstructor
@DS("mysql")
public class IcuOnlinePatientsServiceImpl extends ServiceImpl<IcuOnlinePatientsMapper, IcuOnlinePatients> implements IcuOnlinePatientsService {


//    public List<IcuOnlinePatients> getPatientsWithIsCk(Integer isCk) {
//        // 创建QueryWrapper并添加条件
//        QueryWrapper<IcuOnlinePatients> queryWrapper = new QueryWrapper<>();
//        if (isCk != null) {
//            queryWrapper.eq("is_ck", isCk);  // 假设数据库字段名为 is_ck
//        }
//        // 查询符合条件的数据
//        return this.list(queryWrapper);
//    }

    // 根据 hospitalNumber 查询单个患者，限制查询结果为 1
    public IcuOnlinePatients getPatientByHospitalNumber(String hospitalNumber) {
        QueryWrapper<IcuOnlinePatients> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("hospital_number", hospitalNumber); // 构建查询条件

        // 使用 list 查询，并手动限制结果为 1
        List<IcuOnlinePatients> patients = this.list(queryWrapper);

        // 如果结果不为空，返回第一条记录，否则返回 null
        return (patients.isEmpty()) ? new  IcuOnlinePatients(): patients.get(0);
    }
}
